<template>
  <div class="box">
    <div class="head-fixed">
      <div class="head">
        <div class="head-div">
          <img src="../../assets/zjt2.png" alt="" class="back" @click="back()"/>
        </div>
        <div class="head-search">工作经历</div>
        <div @click="saveWork">保存</div>
      </div>
    </div>
    <div class="content">
      <div class="inpBox">
        <span>公司名称</span>
        <div>
          <input type="text" v-model="ycUserExperience.companyName" placeholder="请输入公司名称"/>
        </div>
      </div>
      <div class="inpBox">
        <span>所属岗位</span>
        <div>
          <input type="text" v-model="ycUserExperience.jobName" placeholder="请输入岗位名称"/>
        </div>
      </div>
      <div class="inpBox">
        <span>工作开始时间</span>
        <div>
          <input type="date" v-model="ycUserExperience.entryTime" placeholder="请输入工作时间"/>
        </div>
      </div>
      <div class="inpBox">
        <span>工作结束时间</span>
        <div>
          <input type="date" v-model="ycUserExperience.departureTime" placeholder="请输入离职时间"/>
        </div>
      </div>
      <!--      <div class="inpBox">-->
      <!--        <span>月薪（元）</span>-->
      <!--        <div>-->
      <!--          <input type="text" v-model="ycUserExperience.salary" placeholder="请输入月薪"/>-->
      <!--        </div>-->
      <!--      </div>-->
      <div class="inpBoxs">
        <div class="inpBox">
          <span>项目经验</span>
          <div style="color:#757575">选填</div>
        </div>
        <textarea name="" id="" placeholder="请描述你的项目经验..." v-model="ycUserExperience.description"></textarea>
      </div>
    </div>
  </div>
</template>

<script>
import {Toast} from 'mint-ui'

export default {
  inject: ['reload'],
  name: 'work',
  components: {},
  created () {
    // created 在模板渲染成html前调用，即通常初始化某些属性值，然后再渲染成视图
    this.init()
  },
  mounted () {
    // mounted在模板渲染成html后调用，通常是初始化页面完成后，再对html的dom节点进行一些需要的操作
  },
  // data() 为变量赋值等
  data () {
    return {
      // status为用户身份，0是求职者，1是招聘者
      status: localStorage.status,
      resumeId: '',
      name: '',
      post: '',
      time: '',
      text: '',
      ycUserExperience: {
        id: 0,
        salary: '',
        description: '',
        companyName: '',
        jobName: '',
        departureTime: '',
        entryTime: ''
      }
    }
  },
  // methods 编写js函数
  methods: {
    notEmpty (val) {
      const re = new RegExp('^[ ]+$') //正则，去除空字符。匹配是否为空
      return !(val == null || val === '' || typeof (val) === 'undefined' || re.test(val))
    },
    saveWork () {
      if (!this.notEmpty(this.ycUserExperience.companyName)) {
        return Toast('请输入公司名称')
      }
      if (!this.notEmpty(this.ycUserExperience.jobName)) {
        return Toast('请输入所属岗位')
      }
      if (!this.notEmpty(this.ycUserExperience.entryTime)) {
        return Toast('请选择工作开始时间')
      }
      if (!this.notEmpty(this.ycUserExperience.departureTime)) {
        return Toast('请选择工作结束时间')
      }
      this.$http({
        url: this.AppURL + '/userExperience/save',
        method: 'post',
        data: {
          id: this.ycUserExperience.id,
          resumeId: this.resumeId,
          salary: this.ycUserExperience.salary,
          description: this.ycUserExperience.description,
          companyName: this.ycUserExperience.companyName,
          jobName: this.ycUserExperience.jobName,
          departureTime: this.ycUserExperience.departureTime,
          entryTime: this.ycUserExperience.entryTime
        }
      }).then(({data}) => {
        if (data && data.code == 0) {
          alert('保存成功')
          this.$router.push('/usersResume')
        }

      }).catch(error => {
        // 错误处理
        console.error('error: ', error)
      })
    },
    init () {
      this.resumeId = this.$route.query.resumeId
      this.$http({
        method: 'get',
        params: {
          userId: this.userId,
        },
        url: 'api/userExperience/infoByResumeId/' + this.resumeId
      }).then(({data}) => {
        if (data && data.code == 0 && data.UserExperience != null) {
          this.ycUserExperience = data.UserExperience
        }
      })

    },
    back () {
      this.$router.go(-1) //返回上一层
    }
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
html,
body,
.tac,
.box,
.tab-left,
.tab-left .el-menu {
  height: 100%;
}

.box {
  width: 100%;
  background: #fff;
}

.head-fixed {
  width: 100%;
  height: 43px;
  position: fixed;
  z-index: 999;
}

.head {
  background: #3e63a8;
  color: #fff;
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.back {
  width: 14px;
  height: 14px;
}

.head div img {
  width: 20px;
  height: 20px;
}

.head-search {
  box-sizing: border-box;
  flex: 1;
  text-align: center;
  font-size: 14px;
}

.content {
  position: relative;
  top: 43px;
  width: 100%;
  box-sizing: border-box;
  padding: 0 20px;
}

.inpBox {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  border-bottom: 1px solid #eee;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 14px;
}

.inpBox input {
  border: 0;
  flex: 1;
  outline: none;
  font-size: 14px;
  height: 30px;
  text-align: right;
}

.inpBox div {
  display: flex;
  align-items: center;
}

.inpBoxs {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-flow: column;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.inpBoxs .inpBox {
  border: 0;
}

.inpBoxs textarea {
  width: 100%;
  height: 150px;
  margin-top: 10px;
  box-sizing: border-box;
  padding: 10px;
}
</style>
